package secondBrush.doubles;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;

public class E03Leetcode844 {
    public boolean backspaceCompare(String s, String t) {
        char[] ss = s.toCharArray();
        char[] tt = t.toCharArray();

        int s1 = 0, s2 = 0;
        for (int i = 0; i < ss.length; i++) {
            if (ss[i] != '#') {
                ss[s1] = ss[i];
                s1++;
            } else {
                s1 = s1 > 1 ? s1 - 1 : 0;
            }
        }

        for (int i = 0; i < tt.length; i++) {
            if (tt[i] != '#') {
                tt[s2] = tt[i];
                s2++;
            } else {
                s2 = s2 > 1 ? s2 - 1 : 0;
            }
        }

        for (int i = 0; i < s1; i++) {
            if (ss[i] != tt[i]) {
                return false;
            }

        }

        return true;
    }

    public static void main(String[] args) {
        String s = "ab#c";
        String t = "ad#c";
        E03Leetcode844 e03Leetcode844 = new E03Leetcode844();
        e03Leetcode844.backspaceCompare(s, t);


    }
}
